home *** CD-ROM | disk | FTP | other *** search
- head 1.4;
- access;
- symbols
- HWGRCSp4:1.4;
- locks; strict;
- comment @ * @;
-
-
- 1.4
- date 93.06.13.15.31.55; author heinz; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 93.06.13.15.28.21; author heinz; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 93.06.13.14.41.53; author heinz; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 93.06.13.14.15.15; author heinz; state Exp;
- branches;
- next ;
-
-
- desc
- @This is an AmigaOS SAS/C version of the rcsfreeze scripts.
- @
-
-
- 1.4
- log
- @An extra \n to make the log file compatible.
- @
- text
- @/*------------------------------------------------------------------------*/
- /* *
- * $Id: rcsfreeze.c,v 1.3 1993/06/13 15:28:21 heinz Exp heinz $
- *
- * $Log: rcsfreeze.c,v $
- * Revision 1.3 1993/06/13 15:28:21 heinz
- * Now makes the file list first and then does the freeze.
- * The MatchXXX routines barf on me if I try to do it "on the fly"
- *
- * Revision 1.2 1993/06/13 14:41:53 heinz
- * Argh! I forgot to remove the trailing \n in the RCS_link.
- *
- * Revision 1.1 1993/06/13 14:15:15 heinz
- * Initial revision
- *
- * */
- /*------------------------------------------------------------------------*/
-
- /*------------------------------------------------------------------------*/
- /*
- This is a SAS/C 6.x replacement for my AmigaOS shell script rcsfreeze.
-
- It should work a lot better for branches. Hopefully it won't freeze the
- branch number anymore, but the highest revision number on that branch
- as it should have done in the first place.
-
- It is a hack and duplicates the shell script functionality just about
- 1:1. I needed it in C to make parsing of the revision number
- possible! This program uses the fact that "rlog -b" gives us the
- revision entry we want. To be sure that we don't read a fake revision
- line in the file description that just happens to be suitable, we check
- for the "----[...]" line first, that comes before every revision entry.
-
- There is one thing though, that is pretty nasty. We need to make a list
- of all the filenames first, because if we process the files while
- reading through the directory, the MatchXX() routines will loose track
- of the current position.
-
- No startup code!
-
- sc $* nostkchk optimize link nostartup strmerge
-
-
- */
-
- /*------------------------------------------------------------------------*/
- #ifndef USE_BUILTIN_MATH
- #define USE_BUILTIN_MATH
- #endif
-
- #ifndef __USE_SYSBASE
- #define __USE_SYSBASE
- #endif
-
- /*------------------------------------------------------------------------*/
- #include <string.h>
- #include <stdlib.h>
- #include <dos.h>
-
- #define BUFSIZ 256
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
-
- /*------------------------------------------------------------------------*/
- #define VERSIONFILE ".rcsfreeze.ver"
- #define LOGFILE ".rcsfreeze.log"
-
- struct FileList
- {
- struct FileList *Next;
- UBYTE Name[0];
- /* Here follows the name! */
- };
-
- /*------------------------------------------------------------------------*/
- static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...);
- static LONG freeze_revs(struct Library *SysBase,
- struct Library *DOSBase,
- STRPTR symrevname);
-
- /*------------------------------------------------------------------------*/
- int main(int argc, char **argv)
- {
- struct Library *SysBase = *((struct Library **)4);
- struct Library *DOSBase = OpenLibrary("dos.library", 37);
-
- if(DOSBase)
- {
- BPTR olddir = CurrentDir(NULL);
- BPTR rcsdir, fh;
- UBYTE buf[BUFSIZ], symrevbuf[BUFSIZ];
- STRPTR symrev = NULL, symrevname;
- LONG versionnumber;
- struct RDArgs *rd;
- UBYTE datebuf[3][20];
- LONG error = 0;
-
- /* Just to get the version string into the code segment ... */
- strcpy(buf, "$VER: rcsfreeze 1.0 (13.6.93) For Joan");
-
- /* First we duplicate the currentdir. So we can restore it later */
- CurrentDir(DupLock(olddir));
-
- if(rd = ReadArgs("SYMREV", (LONG *)&symrev, NULL))
- {
- /* Do we have an RCS_link around? */
- fh = Open("RCS_link", MODE_OLDFILE);
- if(fh)
- {
- LONG len;
-
- /* What's in the link? */
- if(!FGets(fh, buf, BUFSIZ - 1))
- {
- buf[0] = 0;
- } /* if */
-
- len = strlen(buf);
- if(len && buf[len - 1] == '\n')
- {
- buf[--len] = 0;
- } /* if */
-
- Close(fh);
- }
- else
- {
- strcpy(buf, "RCS");
- } /* if */
-
- if(buf[0])
- {
- /* Too laze to check for a dirname. We just try it. */
- rcsdir = Lock(buf, ACCESS_READ);
-
- if(rcsdir)
- {
- UnLock(CurrentDir(rcsdir));
- } /* if */
- } /* if */
-
- /* Create the version and revision files if necessary */
- fh = Open(VERSIONFILE, MODE_OLDFILE);
- if(!fh)
- {
- fh = Open(VERSIONFILE, MODE_NEWFILE);
- if(fh)
- {
- FPuts(fh, "0\n");
- Close(fh);
- } /* if */
-
- fh = Open(LOGFILE, MODE_NEWFILE);
- if(fh)
- {
- Close(fh);
- } /* if */
-
- fh = Open(VERSIONFILE, MODE_OLDFILE);
- } /* if */
-
- /* Lets advance the version number! */
- versionnumber = 1;
- if(fh)
- {
- if(!FGets(fh, buf, BUFSIZ - 1))
- {
- buf[0] = 0;
- } /* if */
-
- StrToLong(buf, &versionnumber);
- versionnumber++;
-
- Close(fh);
-
- fh = Open(VERSIONFILE, MODE_NEWFILE);
- if(fh)
- {
- FPrintf(fh, "%ld\n", versionnumber);
-
- Close(fh);
- }
- else
- {
- error = IoErr();
- } /* if */
- }
- else
- {
- error = IoErr();
- } /* if */
-
- if(!error)
- {
- SPrintf(SysBase, symrevbuf, "C_%ld", versionnumber);
- symrevname = (symrev) ? symrev : symrevbuf;
-
- Printf("rcsfreeze: symbolic revision number computed: '%s'\n", symrevbuf);
- Printf(" symbolic revision number used: '%s'\n", symrevname);
- PutStr("\n The two differ only when rcsfreeze was invoked with an argument.\n\n");
- PutStr("Give a log message, summarizing changes (end with EOF, CTRL-\, or single '.')\n");
-
- /* We need the date for the freeze */
- {
- struct DateTime dt;
-
- DateStamp(&dt.dat_Stamp);
- dt.dat_Format = FORMAT_DOS; /* Compatibility to the old script */
- dt.dat_Flags = 0;
- dt.dat_StrDay = datebuf[0];
- dt.dat_StrDate = datebuf[1];
- dt.dat_StrTime = datebuf[2];
-
- DateToStr(&dt);
- }
-
- /* Let us append the revision freeze text */
- fh = Open(LOGFILE, MODE_OLDFILE);
- if(fh)
- {
- Seek(fh, 0, OFFSET_END);
-
- FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n\n",
- symrevname, symrevbuf,
- datebuf[0],
- datebuf[1],
- datebuf[2]);
-
- while(FGets(Input(), buf, BUFSIZ - 1))
- {
- if(buf[0] == '.' && (!buf[1] || buf[1] == '\n'))
- {
- break;
- } /* if */
-
- FPuts(fh, buf);
- } /* while */
-
- Close(fh);
- }
- else
- {
- error = IoErr();
- } /* if */
-
- if(!error)
- {
- error = freeze_revs(SysBase, DOSBase, symrevname);
- } /* if */
- } /* if */
-
- FreeArgs(rd);
- }
- else
- {
- error = IoErr();
- } /* if */
-
- UnLock(CurrentDir(olddir));
-
- if(error)
- {
- PrintFault(error, NULL);
- } /* if */
-
- CloseLibrary(DOSBase);
- } /* if */
-
- return(0);
-
-
- } /* main */
-
- /*------------------------------------------------------------------------*/
- static void SPutC(void)
- {
- __emit(0x16c0); /* MOVE.B d0,(a3)+ */
-
- } /* SPutC */
-
- /*------------------------------------------------------------------------*/
- static void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...)
- {
- RawDoFmt(format, (APTR) ((&format)+1), SPutC, buf);
-
- } /* SPrintf */
-
- /*------------------------------------------------------------------------*/
- static STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template)
- {
- STRPTR cp;
- ULONG val;
- BPTR lock;
-
- cp = template;
- cp += strlen(cp);
- for (val = (ULONG) FindTask(NULL) ; ; )
- {
- if (*--cp == 'X')
- {
- *cp = (val & 0x0f) + '0';
- if(*cp > '9')
- {
- *cp += 7;
- } /* if */
- val >>= 4;
- }
- else if (*cp != '.')
- {
- break;
- } /* if */
- } /* for */
-
- if (*++cp != 0)
- {
- *cp = 'A';
- while (lock = Lock(template, ACCESS_READ))
- {
- UnLock(lock);
-
- if (*cp == 'Z')
- {
- *template = 0;
- break;
- } /* if */
- ++*cp;
- } /* while */
- }
- else
- {
- if (lock = Lock(template, ACCESS_READ))
- {
- UnLock(lock);
- *template = 0;
- } /* if */
- } /* if */
-
- return template;
-
- } /* mktemp */
-
- /*------------------------------------------------------------------------*/
- static struct FileList *GetFileList(struct Library *SysBase,
- struct Library *DOSBase,
- LONG *errorp)
- {
- struct AnchorPath __aligned ap;
- LONG error;
- struct FileList *head = NULL;
-
- memset(&ap, 0, sizeof(ap));
-
- ap.ap_BreakBits = SIGBREAKF_CTRL_C;
-
- error = MatchFirst("#?,v", &ap);
- if(!error)
- {
- for(; !error; error = MatchNext(&ap))
- {
- LONG len = strlen(ap.ap_Info.fib_FileName);
- struct FileList *fl = AllocVec(sizeof(*fl) + len + 1, MEMF_ANY);
-
- if(fl)
- {
- fl->Next = head;
- strcpy(fl->Name, ap.ap_Info.fib_FileName);
-
- head = fl;
- }
- else
- {
- error = ERROR_NO_FREE_STORE;
- break;
- } /* if */
- } /* for */
- MatchEnd(&ap);
- } /* if */
-
- if(error == ERROR_NO_MORE_ENTRIES)
- {
- error = 0;
- } /* if */
-
- *errorp = error;
-
- return(head);
-
- } /* GetFileList */
-
- /*------------------------------------------------------------------------*/
- static void FreeFileList(struct Library *SysBase, struct FileList *fl)
- {
- struct FileList *flnext;
-
- for(; fl; fl = flnext)
- {
- flnext = fl->Next;
-
- FreeVec(fl);
- } /* for */
-
- } /* FreeFileList */
-
- /*------------------------------------------------------------------------*/
- static LONG freeze_revs(struct Library *SysBase,
- struct Library *DOSBase,
- STRPTR symrevname)
- {
- LONG error;
- UBYTE buf[BUFSIZ];
- struct FileList *head, *fl;
-
- head = GetFileList(SysBase, DOSBase, &error);
-
- if(!error)
- {
- for(fl = head; !error && fl; fl = fl->Next)
- {
- BPTR fh;
- char tmpbuf[20],cmdbuf[BUFSIZ];
-
- strcpy(tmpbuf, "PIPE:rfXXX.XXX");
- if(mktemp(SysBase, DOSBase, tmpbuf))
- {
- SPrintf(SysBase, cmdbuf, "rlog >%s -b \"%s\"\n",
- tmpbuf, fl->Name);
-
- if(!(error = SystemTags(cmdbuf,
- SYS_UserShell, TRUE,
- TAG_END)))
- {
- fh = Open(tmpbuf, MODE_OLDFILE);
- if(fh)
- {
- while(FGets(fh, buf, BUFSIZ - 1) && !error)
- {
- if(strlen(buf) > 10 && !memcmp(buf, "----------", 10))
- {
- if(FGets(fh, buf, BUFSIZ - 1))
- {
- if(strlen(buf) > 10 &&
- !memcmp(buf, "revision ", 9))
- {
- /* This is the version number we are
- looking for!! */
- STRPTR version = &buf[9];
- ULONG len = strlen(version);
-
- if(version[len - 1] == '\n')
- {
- version[--len] = 0;
-
- } /* if */
-
- if(len > 2)
- {
- Printf("rcsfreeze: '%s' %s\n",
- version, fl->Name);
-
- SPrintf(SysBase, cmdbuf, "rcs -q \"-n%s:%s\" \"%s\"\n",
- symrevname,
- version,
- fl->Name);
- error = SystemTags(cmdbuf,
- SYS_UserShell, TRUE,
- TAG_END);
- } /* if */
- break;
- } /* if */
- } /* if */
- } /* if */
- } /* while */
-
- Close(fh);
- }
- else
- {
- error = ERROR_OBJECT_NOT_FOUND;
- } /* if */
- } /* if */
- }
- else
- {
- error = ERROR_BAD_TEMPLATE;
- } /* if */
-
- if(error)
- {
- break;
- } /* if */
- } /* for */
- } /* if */
-
- FreeFileList(SysBase, head);
-
- return(error);
-
- } /* freeze_revs */
-
- /*------------------------------------------------------------------------*/
-
- /* Ende des Quelltextes */
-
- @
-
-
- 1.3
- log
- @Now makes the file list first and then does the freeze.
- The MatchXXX routines barf on me if I try to do it "on the fly"
- @
- text
- @d3 1
- a3 1
- * $Id: rcsfreeze.c,v 1.2 1993/06/13 14:41:53 heinz Exp heinz $
- d6 4
- d228 1
- a228 1
- FPrintf(fh, "\nVersion: %s(%s), Date: %s %s %s\n",
- @
-
-
- 1.2
- log
- @Argh! I forgot to remove the trailing \n in the RCS_link.
- @
- text
- @d3 1
- a3 1
- * $Id: rcsfreeze.c,v 1.1 1993/06/13 14:15:15 heinz Exp heinz $
- d6 3
- d30 5
- d59 1
- d69 7
- d77 4
- a80 4
- void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...);
- LONG freeze_revs(struct Library *SysBase,
- struct Library *DOSBase,
- STRPTR symrevname);
- d283 1
- a283 1
- void SPrintf(struct Library *SysBase, STRPTR buf, STRPTR format, ...)
- d290 1
- a290 1
- STRPTR mktemp(struct Library *SysBase, struct Library *DOSBase, STRPTR template)
- d344 3
- a346 3
- LONG freeze_revs(struct Library *SysBase,
- struct Library *DOSBase,
- STRPTR symrevname)
- d350 1
- a350 1
- UBYTE buf[BUFSIZ];
- d361 59
- d427 1
- a427 1
- tmpbuf, ap.ap_Info.fib_FileName);
- d459 1
- a459 1
- version, ap.ap_Info.fib_FileName);
- d464 1
- a464 1
- ap.ap_Info.fib_FileName);
- a492 2
-
- MatchEnd(&ap);
- d495 1
- a495 4
- if(error == ERROR_NO_MORE_ENTRIES)
- {
- error = 0;
- } /* if */
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d3 1
- a3 1
- * $Id: rcsfreeze.c,v 1.1 1993/06/13 13:52:23 heinz Exp $
- d6 1
- a6 1
- * Revision 1.1 1993/06/13 13:52:23 heinz
- a8 1
- *
- d95 1
- d101 6
- @
-